package chapter13.section3;
/*程序13-2 利用Statement执行sql语句，对数据库进行直接操作*/

import java.sql.*;
import java.util.UUID;

public class TableDML {
    public static void main(String[] args) {
        String url = " jdbc:mysql://localhost:3306/bank?user=root&password=123456 ";
        Connection con = null;
        try {
            con = DriverManager.getConnection(url);
            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            String sql = "create table tb_account(" + "id  nvarchar(50) not null," + "name nvarchar(10) null," + "balance int null," + "primary key (id))";
            stmt.executeUpdate(sql);
            UUID uuid = UUID.randomUUID();
            sql = "insert into tb_account(id,name,balance) values('" + uuid + "','丁美丽',1000)";
            stmt.executeUpdate(sql);
            sql = "update tb_account set balance=2000 where " + "id='" + uuid + "'";
            stmt.executeUpdate(sql);
            stmt.close();
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}